package com.ctrip.study.refactor.splitTemporaryVariable;

public class Travel {
	
	private int _primaryForce;
	
	private int _mass;
	
	private int _delay;
	
	private int _secondaryForce;
	
	public Travel(int primaryForce, int mass, int delay, int secondaryForce) {
		this._primaryForce = primaryForce;
		this._mass = mass;
		this._delay = delay;
		this._secondaryForce = secondaryForce;
	}

	double getDistanceTravelled(int time) {
		return primaryResult(time) + secondaryResult(time);
	}

	public double secondaryResult(int time) {
		if (secondaryTime(time) > 0) {
			return primaryVel() * secondaryTime(time) + 0.5 * secondaryAcc() * secondaryTime(time)
					* secondaryTime(time);
		}
		return 0;
	}

	public double primaryResult(int time) {
		return 0.5 * primaryAcc() * primaryTime(time) * primaryTime(time);
	}

	public int secondaryAcc() {
		return (_primaryForce + _secondaryForce) / _mass;
	}

	public int primaryVel() {
		return primaryAcc() * _delay;
	}

	public int secondaryTime(int time) {
		return time - _delay;
	}

	public int primaryTime(int time) {
		return Math.min(time, _delay);
	}

	
	public int primaryAcc() {
		return _primaryForce / _mass;
	}

}
